
package saxParseXML;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import javax.xml.parsers.SAXParser; 
import javax.xml.parsers.SAXParserFactory;


public class TestSaxParseXml {
	
	
	
	     
	     public static List<Map<String,String>> ReadXML(String uri,String NodeName){
	        try {
	             //创建一个XML的解析工厂对象
	            SAXParserFactory parserFactory=SAXParserFactory.newInstance();
	             //创建一个XML的解析对象
	            SAXParser parser=parserFactory.newSAXParser();
	             //创建一个解析助手类
	            SaxParseXml saxParser=new SaxParseXml("rss");
	            parser.parse(uri, saxParser);
	             return saxParser.getList();
	         } catch (Exception e) {
	             e.printStackTrace();
	         }finally{
	             
	         }
	        return null;
	    }
	     
	     public static void main(String[] args) {
	    	        ArrayList<Map<String, String>> list=(ArrayList<Map<String, String>>) TestSaxParseXml.ReadXML("src/网易手机各地行情.xml","rss");
	    	         for(int i=0;i<list.size();i++){
	    	            HashMap<String, String> temp=(HashMap<String, String>) list.get(i);
	    	                Iterator<String> iterator=temp.keySet().iterator();
	    	                while(iterator.hasNext()){
	    	                    String key=iterator.next().toString();
	    	                     String value=temp.get(key);
	    	                    System.out.println(key+"###"+value+"####");
	    	                }
	    	         }
	    	         System.out.println(list.toString());
	    	     }
	    	 
	    	   

}
